﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HHCommon;

namespace HHWeb.SystemManage.Users
{
    public partial class PassWordM : Base
    {
        EncAndDec encanddec = new EncAndDec();
        Help help = new Help();
        NoHtml nohtml = new NoHtml();
        public string UserNumber = string.Empty;
        public string UserCode = string.Empty;
        public string pwd = string.Empty;
        HHBLL.Users B = new HHBLL.Users();
        HHModel.Users M = new HHModel.Users();
        public string Command = "My";
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (help.GetHttpMethodBool())
                {
                    UserNumber = Request.Form["UserNumber"].ToString();
                    M.UserPassWord = help.GetMD5(Request.Form["NewPassWord"].ToString());
                    if (Request.Form["Command"].ToString() == "My")
                    {
                        if (!B.Exists(UserNumber, help.GetMD5(Request.Form["UserPassWord"].ToString())))
                        {
                            MessageBox.ResponseScript(this.Page, "旧密码错误！", "javascript:history.go(-1)");
                            return;
                        }
                    }
                    if (B.UpdatePwdByUserNumber(UserNumber, M.UserPassWord))
                        Response.Write("<script language =\"javascript\">alert('修改成功！'); window.open('/SystemManage/Login.aspx','_top')</script>");
                    else
                        MessageBox.ResponseScript(this.Page, "修改失败！", "javascript:history.go(-1)");
                }
                else
                {
                    if (help.IFPageParameter())
                    {
                        int ID = Convert.ToInt32(Request.QueryString["ID"].ToString());
                        M = B.GetModel(ID);
                        if (M != null)
                        {
                            UserNumber = M.UserNumber;
                            UserCode = M.UserCode;
                            Command = "Other";
                        }
                        else
                        {
                            MessageBox.ShowAndRedirect(this.Page, "该数据不存在！", "List.aspx");
                            return;
                        }
                    }
                    else
                    {
                        UserNumber = encanddec.DESDecrypting(help.GetCookie("UserNumber"));
                        UserCode = encanddec.DESDecrypting(help.GetCookie("UserCode"));
                    }
                }
            }
            catch
            {
                MessageBox.ResponseScript(this.Page, "操作错误，请联系管理员！", "javascript:history.go(-1)");
                return;
            }
        }
    }
}